package com.wang;

import java.nio.channels.NonWritableChannelException;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;

/**
 * @ProjectName: untitled
 * @Titile: TreeSetDemo
 * @Author: 王亦凡1
 * @Description: TODO
 */
public class TreeSetDemo {
    public static void main(String[] args) {
        TreeSet<Integer>set1=new TreeSet<>();
        //1--自动将1包装成integer对象----自动装箱
//        Integer i1=Integer.valueOf(1);
//        int a=i1+2;
        set1.add(5);
        set1.add(4);
        set1.add(3);
        set1.add(2);
        set1.add(1);
        for(Integer integer: set1){
            System.out.println(integer);
        }
       // System.out.println(set1);
    }
    public static void test1(){
        TreeSet<Student>set=new TreeSet<>();
        set.add(new Student("王彪",19));
        set.add(new Student("王源",20));
        set.add(new Student("王俊凯",23));
        set.add(new Student("王德法",28));

        for (Student student:set){
            System.out.println(student.getName()+"--"+student.getAge());
        }
    }
    public static void test2(){

        Comparator<Student>comparator=(o1,o2)->o1.getAge()-o2.getAge();

        TreeSet<Student>set = new TreeSet<>(comparator);
        set.add(new Student("王彪",19));
        set.add(new Student("王源",20));
        set.add(new Student("王俊凯",23));
        set.add(new Student("王德法",28));
        for(Student student:set){
            System.out.println(student.getName()+"--"+student.getAge());
        }
    }
      public static int sum(int...a) {
          int total = 0;
          for (int i = 0; i < a.length; i++) {
              total += a[i];
          }
          return total;
      }

}